package com.itheima.tanhua.web;


import cn.hutool.core.lang.ObjectId;
import com.itheima.tanhua.pojo.mongo.Movement;
import com.itheima.tanhua.service.MovementService;
import com.itheima.tanhua.vo.mongo.MovementsVo;
import com.itheima.tanhua.vo.mongo.pageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author 芝士雪豹
 * @create 2022/9/24/20:01
 */
@RestController
@RequestMapping("movement")
public class MovementController {

    @Autowired
    private MovementService movementService;

    /**
     * 发布动态
     *
     * @param movement
     * @param imageContent
     * @return
     * @throws IOException
     */
    @PostMapping
    public ResponseEntity movements(Movement movement, MultipartFile imageContent[]) throws IOException {
        movementService.publish(movement, imageContent);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询圈子个人动态
     *
     * @return
     */
    @GetMapping("all")
    public ResponseEntity findByUserId(Long userId,
                                       @RequestParam(value = "1") Integer page,
                                       @RequestParam(value = "10") Integer pagesize) {
        pageResult ps = movementService.findByUserId(userId, page, pagesize);
        return ResponseEntity.ok(ps);
    }

    /**
     * 查询好友动态
     *
     * @return
     */
    @GetMapping("movements")
    public ResponseEntity movements(@RequestParam(value = "1") Integer page,
                                    @RequestParam(value = "10") Integer pagesize) {
        pageResult ps = movementService.findFriendMovement(page, pagesize);
        return ResponseEntity.ok(ps);
    }

    /**
     * 查询推荐动态
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("recommend")
    public ResponseEntity recommend(@RequestParam(value = "1") Integer page,
                                    @RequestParam(value = "10") Integer pagesize) {
        pageResult ps = movementService.findRecommend(page, pagesize);
        return ResponseEntity.ok(ps);
    }

    /**
     * 根据id查询动态
     */
    @GetMapping("/{id}")
    public ResponseEntity findById(@PathVariable("id") String movementId) {
        MovementsVo vo = movementService.findMovementById(movementId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 点赞
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String movementId) {
        Integer count = movementService.likeComment(movementId);
        return ResponseEntity.ok(count);
    }

    /**
     * 取消点赞
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String movementId) {
        Integer count = movementService.dislikeComment(movementId);
        return ResponseEntity.ok(count);
    }

    //喜欢
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") String movementId) {
        Integer count = movementService.loveComment(movementId);
        return ResponseEntity.ok(count);
    }

    /**
     * 取消点赞
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") String movementId) {
        Integer count = movementService.unloveComment(movementId);
        return ResponseEntity.ok(count);
    }
    //谁看过我
    @GetMapping("visitors")
    public ResponseEntity visitors() {
        return ResponseEntity.ok(new Object[]{});
    }
}
